package com.cty.LinkedList;

public class question03 {
    //单链表的反转(传入一个头节点)
    public static void invert(heroNode head) {
        //判断链表是否为空和只有一个有效节点
        if (head.next == null || head.next.next == null) {
            //如果成立链表不用反转
            return;
        }
        //创建一个反转后链表的临时头节点
        heroNode reverseHead = new heroNode(0, "", "");
        //创建临时变量
        heroNode temp = head.next;
        //创建一个暂存节点的变量
        heroNode node = null;
        //遍历取出节点
        while (temp != null) {
            node = temp;
            temp = temp.next;
            node.next = reverseHead.next;
            reverseHead.next = node;
        }
        head.next = reverseHead.next;
    }
}